/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.leospae.handler;

import java.util.HashMap;
import java.util.Hashtable;

import com.leospa.bean.Command_0;
import com.leospa.clients.DateClient;
import com.leospa.main.MainScreen;
import com.leospa.main.OptionScreen;
import com.leospa.properties.CommandPropertiesFile;
import com.leospa.properties.ConfigPropertiesFile;

/**
 *
 * @author ADMIN
 */
public class Command_0_handler {


	String[] parts2;

	public String sendCammand_0(MainScreen mainScreen,javax.swing.GroupLayout layout) {
		if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println(ConfigPropertiesFile.SERVER_ADDRESS+","+ConfigPropertiesFile.PORT+","+"CMD:0;"+","+ConfigPropertiesFile.TIMEOUT_MS);}
		String str = DateClient.SocketInterface(ConfigPropertiesFile.SERVER_ADDRESS,ConfigPropertiesFile.PORT, "CMD:0;", ConfigPropertiesFile.TIMEOUT_MS);
		if (str != null) {
			if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println("Data Successfully Fetched: "+str);}
		} else {
			if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println("Data Fetch Unsuccessfull: "+str);}
			if (ConfigPropertiesFile.DEMO_MODE == true) {
				new OptionScreen(mainScreen,layout).setVisible(true);
				if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println("Timeout");}
			}
		}

		return str;
	}

	public Hashtable getCommand0(MainScreen mainScreen,javax.swing.GroupLayout layout) {
		String command0 = null;
		HashMap<String, String> hmap = new HashMap<String, String>();
		
		if (ConfigPropertiesFile.DEMO_MODE == true) {
			if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println(ConfigPropertiesFile.SERVER_ADDRESS+","+ConfigPropertiesFile.PORT+","+"CMD:0;"+","+ConfigPropertiesFile.TIMEOUT_MS);}
			command0 = CommandPropertiesFile.Command_0;
			if(ConfigPropertiesFile.DEBUG_MODE_ON == true){System.out.println("Demo Command 0 Values: "+command0);}
		
		} else {
			if(ConfigPropertiesFile.DEBUG_MODE_ON == true){System.out.println("I am Trying to fetch Command 0 Data.");}
			command0 = sendCammand_0(mainScreen,layout);
			if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println("Command 0 Values: "+command0);}
		}

		Hashtable<String, Command_0> command_0_hash = new Hashtable<String, Command_0>();
		if (command0 != null) {
			// for number of Label behalf of server response
			int noOflabel = command0.split("SOLARIUMID:").length - 1;
			if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println("Number of Label " + noOflabel);}

			
			String[] data = command0.split("SOLARIUMID:");
			parts2 = new String[data.length];

			for (int i = 1; i < data.length; i++) {
				String result = data[i];
				String resultSt[] = result.split(";");

				// Name
				String name[] = resultSt[1].split(":");
				if(name[1].trim().equals("null")){
					continue;
				}					
				Command_0 command_0 = new Command_0();
				command_0.setNAME(name[1].trim());
				
				// SOLARIUMID
				command_0.setSOLARIUMID(resultSt[0].trim());


				// MINTIME
				String min_time[] = resultSt[2].split(":");
				command_0.setMINTIME(min_time[1].trim());

				// MAXTIME
				String max_time[] = resultSt[3].split(":");
				command_0.setMAXTIME(max_time[1].trim());

				// STEPTIME
				String steptime[] = resultSt[4].split(":");
				command_0.setSTEPTIME(steptime[1].trim());

				// MINPRICE
				String min_price[] = resultSt[5].split(":");
				command_0.setMINPRICE(min_price[1].trim());

				// STEPPRICE
				String step_price[] = resultSt[6].split(":");
				command_0.setSTEPPRICE(step_price[1].trim());

				// PRETIME
				String pre_time[] = resultSt[7].split(":");
				command_0.setPRETIME(pre_time[1].trim());

				// AFTER TIME
				String after_time[] = resultSt[8].split(":");
				command_0.setAFTER_TIME(after_time[1].trim());

				// SHOPPINGCART
				String sho_cart[] = resultSt[9].split(":");
				command_0.setSHOPPINGCART(sho_cart[1].trim());

				command_0_hash.put(command_0.getSOLARIUMID(), command_0);
			}
		}
		return command_0_hash;
	}

}
